package com.buaa.aiguangxi.controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.buaa.aiguangxi.service.InstanceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@CrossOrigin
@RestController
public class CommonController {
    @Autowired
    InstanceService instanceService;
    @PostMapping("/common/getRunning")
    public Map<String,Object> getRunning(@RequestBody Map<String,Object> params){
        Map<String,Object> ret=new HashMap<>();
        int sceneId=Integer.parseInt(params.get("sceneid").toString());
        List<Map<String,Object>> instanceList=instanceService.getRunningInstances(sceneId);
        List<Map<String,Object>> runningList=new ArrayList<>();
        for (Map<String,Object> instance:instanceList){
            Map<String,Object> running=new HashMap<>();
            running.put("title",instance.get("instanceName").toString());
            running.put("time",instance.get("createTime").toString().replace("T"," "));
            running.put("id",Integer.valueOf(instance.get("instanceId").toString()));
            runningList.add(running);
        }
        ret.put("runninglist",runningList);
        ret.put("success",true);
        ret.put("msg","无异常");
        return ret;
    }
    @PostMapping("/common/getTraining")
    public Map<String,Object> getTraining(@RequestBody Map<String,Object> params){
        Map<String,Object> ret=new HashMap<>();
        int sceneId=Integer.valueOf(params.get("sceneid").toString());
        List<Map<String,Object>> instanceList=instanceService.getTrainingInstances(sceneId);
        List<Map<String,Object>> trainingList=new ArrayList<>();
        for (Map<String,Object> instance:instanceList){
            Map<String,Object> running=new HashMap<>();
            running.put("title",instance.get("instanceName").toString());
            running.put("time",instance.get("createTime").toString().replace("T"," "));
            running.put("id",Integer.valueOf(instance.get("instanceId").toString()));
            trainingList.add(running);
        }
        ret.put("traininglist",trainingList);
        ret.put("success",true);
        ret.put("msg","无异常");
        return ret;
    }
    @PostMapping("/common/getSceneDetails")
    public JSONObject getSceneDetails(@RequestBody Map<String,Object> params){
        int sceneId=Integer.valueOf(params.get("sceneid").toString());
        JSONObject jsonObject= JSON.parseObject("{\n" +
                "  \"list\": [\n" +
                "    {\n" +
                "      \"title\":\"收费站拥堵预警模型\",\n" +
                "      \"target\": \"模型名称\",\n" +
                "      \"kind\": \"视频跟踪类\",\n" +
                "      \"time\": \"2021-10-1\",\n" +
                "      \"description\": \"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean euismod bibendum laoreet. Proin gravida dolor sit amet lacus accumsan et viverra justo commodo. Proin sodales pulvinar sic tempor. Sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Nam fermentum, nulla luctus pharetra vulputate, felis tellus mollis orci, sed rhoncus pronin sapien nunc accuan eget.Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean euismod bibendum laoreet. Proin gravida dolor sit amet lacus accumsan et viverra justo commodo. Proin sodales pulvinar sic tempor. Sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Nam fermentum, nulla luctus pharetra vulputate, felis tellus mollis orci, sed rhoncus pronin sapien nunc accuan eget.Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean euismod bibendum laoreet. Proin gravida dolor sit amet lacus accumsan et viverra justo commodo. Proin sodales pulvinar sic tempor. Sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Nam fermentum, nulla luctus pharetra vulputate, felis tellus mollis orci, sed rhoncus pronin sapien nunc accuan\"\n" +
                "    },\n" +
                "    {\n" +
                "      \"title\":\"门架间车辆流速流量计算\",\n" +
                "      \"target\": \"模型名称\",\n" +
                "      \"kind\": \"统计分析类\",\n" +
                "      \"time\": \"2021-10-1\",\n" +
                "      \"description\": \"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean euismod bibendum laoreet. Proin gravida dolor sit amet lacus accumsan et viverra justo commodo. Proin sodales pulvinar sic tempor. Sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Nam fermentum, nulla luctus pharetra vulputate, felis tellus mollis orci, sed rhoncus pronin sapien nunc accuan eget.Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean euismod bibendum laoreet. Proin gravida dolor sit amet lacus accumsan et viverra justo commodo. Proin sodales pulvinar sic tempor. Sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Nam fermentum, nulla luctus pharetra vulputate, felis tellus mollis orci, sed rhoncus pronin sapien nunc accuan eget.Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean euismod bibendum laoreet. Proin gravida dolor sit amet lacus accumsan et viverra justo commodo. Proin sodales pulvinar sic tempor. Sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Nam fermentum, nulla luctus pharetra vulputate, felis tellus mollis orci, sed rhoncus pronin sapien nunc accuan\"\n" +
                "    },\n" +
                "    {\n" +
                "      \"title\":\"长短时预测\",\n" +
                "      \"target\": \"模型名称\",\n" +
                "      \"kind\": \"视频跟踪类\",\n" +
                "      \"time\": \"2021-10-1\",\n" +
                "      \"description\": \"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean euismod bibendum laoreet. Proin gravida dolor sit amet lacus accumsan et viverra justo commodo. Proin sodales pulvinar sic tempor. Sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Nam fermentum, nulla luctus pharetra vulputate, felis tellus mollis orci, sed rhoncus pronin sapien nunc accuan eget.Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean euismod bibendum laoreet. Proin gravida dolor sit amet lacus accumsan et viverra justo commodo. Proin sodales pulvinar sic tempor. Sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Nam fermentum, nulla luctus pharetra vulputate, felis tellus mollis orci, sed rhoncus pronin sapien nunc accuan eget.Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean euismod bibendum laoreet. Proin gravida dolor sit amet lacus accumsan et viverra justo commodo. Proin sodales pulvinar sic tempor. Sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Nam fermentum, nulla luctus pharetra vulputate, felis tellus mollis orci, sed rhoncus pronin sapien nunc accuan\"\n" +
                "    },\n" +
                "    {\n" +
                "      \"title\":\"桥梁隧道保有量\",\n" +
                "      \"target\": \"模型名称\",\n" +
                "      \"kind\": \"统计分析类\",\n" +
                "      \"time\": \"2021-10-1\",\n" +
                "      \"description\": \"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean euismod bibendum laoreet. Proin gravida dolor sit amet lacus accumsan et viverra justo commodo. Proin sodales pulvinar sic tempor. Sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Nam fermentum, nulla luctus pharetra vulputate, felis tellus mollis orci, sed rhoncus pronin sapien nunc accuan eget.Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean euismod bibendum laoreet. Proin gravida dolor sit amet lacus accumsan et viverra justo commodo. Proin sodales pulvinar sic tempor. Sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Nam fermentum, nulla luctus pharetra vulputate, felis tellus mollis orci, sed rhoncus pronin sapien nunc accuan eget.Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean euismod bibendum laoreet. Proin gravida dolor sit amet lacus accumsan et viverra justo commodo. Proin sodales pulvinar sic tempor. Sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Nam fermentum, nulla luctus pharetra vulputate, felis tellus mollis orci, sed rhoncus pronin sapien nunc accuan\"\n" +
                "    },\n" +
                "    {\n" +
                "      \"title\":\"雾灾监测与预测、风险等级划分\",\n" +
                "      \"target\": \"模型名称\",\n" +
                "      \"kind\": \"视频跟踪类\",\n" +
                "      \"time\": \"2021-10-1\",\n" +
                "      \"description\": \"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean euismod bibendum laoreet. Proin gravida dolor sit amet lacus accumsan et viverra justo commodo. Proin sodales pulvinar sic tempor. Sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Nam fermentum, nulla luctus pharetra vulputate, felis tellus mollis orci, sed rhoncus pronin sapien nunc accuan eget.Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean euismod bibendum laoreet. Proin gravida dolor sit amet lacus accumsan et viverra justo commodo. Proin sodales pulvinar sic tempor. Sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Nam fermentum, nulla luctus pharetra vulputate, felis tellus mollis orci, sed rhoncus pronin sapien nunc accuan eget.Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean euismod bibendum laoreet. Proin gravida dolor sit amet lacus accumsan et viverra justo commodo. Proin sodales pulvinar sic tempor. Sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Nam fermentum, nulla luctus pharetra vulputate, felis tellus mollis orci, sed rhoncus pronin sapien nunc accuan\"\n" +
                "    },\n" +
                "    {\n" +
                "      \"title\":\"事件下时空影响分析\",\n" +
                "      \"target\": \"模型名称\",\n" +
                "      \"kind\": \"视频跟踪类\",\n" +
                "      \"time\": \"2021-10-1\",\n" +
                "      \"description\": \"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean euismod bibendum laoreet. Proin gravida dolor sit amet lacus accumsan et viverra justo commodo. Proin sodales pulvinar sic tempor. Sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Nam fermentum, nulla luctus pharetra vulputate, felis tellus mollis orci, sed rhoncus pronin sapien nunc accuan eget.Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean euismod bibendum laoreet. Proin gravida dolor sit amet lacus accumsan et viverra justo commodo. Proin sodales pulvinar sic tempor. Sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Nam fermentum, nulla luctus pharetra vulputate, felis tellus mollis orci, sed rhoncus pronin sapien nunc accuan eget.Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean euismod bibendum laoreet. Proin gravida dolor sit amet lacus accumsan et viverra justo commodo. Proin sodales pulvinar sic tempor. Sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Nam fermentum, nulla luctus pharetra vulputate, felis tellus mollis orci, sed rhoncus pronin sapien nunc accuan\"\n" +
                "    }\n" +
                "  ]\n" +
                "}\n");
        return jsonObject.getJSONArray("list").getJSONObject(sceneId-1);
    }
}
